﻿#include "RankingListMgr.h"

#include "../../include/Common/GlobalDefine.h"
#include "CenterService.h"
#include "Camp/CampMgr.h"
#include "base/core/log.h"
#include "Camp/CampMgr.h"
#include "Active/ActiveCharacterMgr.h"
#include "Arena/ArenaMgr.h"
#include "Union/UnionMgr.h"
#include "Common/TableData/FunctionunlockFunctionUnlockCfg.h"
#include "Common/TableData/OperateHuodongCfg.h"
#include "Common/TableData/OperateJiangliCfg.h"
#include "MailCenter/MailManager.h"
#include "ProtoBuffer/ServerInternalProtocol.pb.h"
#include "ProtoBuffer/ServerToClientCmd.pb.h"
const uint32_t g_constRandingListPageCount = 10;  //每页显示条目数

const uint32_t g_constUpDateSaveInterval = 1000 * 1;  //1分钟

int CmpCharacterLevel(const stRankNode & left,const stRankNode & right)
{
	return left._value()>right._value();
}

int CmpClanFight(const RankingListClanData & left, const RankingListClanData & right)
{
	return left.fightvalue() > right.fightvalue();
}


CRankingListMgr::CRankingListMgr()
//m_pLevelPool(nullptr)
//, m_pFightValuePool(nullptr)
//, m_pFightGoldPool(nullptr)
//, m_pFightDiamondPool(nullptr)
//, m_pKillPointPool(nullptr)
{
	Reset();
}

CRankingListMgr::~CRankingListMgr()
{
	Reset();
}
void CRankingListMgr::Reset()
{
	//m_vLevel.clear();
	m_vCurrentTimeLevel.clear();
	for (int i = 0; i < ECHARACTER_PROF_ARCHER;++i)
	{
		//m_arrFightValue[i].clear();
		m_arrCurrentTimeFightValue[i].clear();
	}

	//m_vGold.clear();
	//m_vCurrentTimeGold.clear();
//	m_vDiamond.clear();
//	m_vCurrentTimeDiamond.clear();
	m_vAllKill.clear();
	m_vLightKill.clear();
	m_vBlackKill.clear();
	m_vAllPristige.clear();
	m_vLightPristige.clear();
	m_vBlackPristige.clear();
	m_arrAllProFight.clear();
	m_bSaveFlag = false;
	m_i64FreshTime = 0;
	m_bLoadFlag = false;
	m_bOperateActiveFightReword = false;
	m_bOperateActiveLevelReword = false;
	m_vFightTitle.clear();
	m_vLevelTitle.clear();

	for (int i = 0; i < ACHIEVEMENT_TYPE_ADVENTURE; ++i)
	{
		//m_arrAchievementPoint[i].clear();
		m_arrCurrentTimeAchievementPoint[i].clear();
	}

	m_vArenaRankInfo.clear();
	m_vClanRank.clear();
	//m_vClanContribute.clear();
	m_vClanCurrentTimeContribute.clear();
	//m_vClanWeekContribute.clear();
	m_vClanCurrentTimeWeekContribute.clear();
	m_vAllClanRank.clear();
}

bool CRankingListMgr::Init()
{
	//m_pLevelPool = new ObjectPool<RankingListLevelData>(100, false);
	//m_pFightValuePool = new ObjectPool<RankingListFightValueData>(400, false);
	//m_pFightGoldPool = new ObjectPool<RankingListGoldData>(100, false);
	//m_pFightDiamondPool = new ObjectPool<RankingListDiamondData>(100, false);
	//m_pKillPointPool = new ObjectPool<RankingListKillPoingData>(300, false);
	IMessageDispatch *pMessageDispatch = g_GetCenterService()->GetServiceMessageDispatch();
	if (nullptr == pMessageDispatch)
	{
		MMOLOG_FMT_ERROR("[center] MailManager::Init....nullptr == pMessageDispatch ");
		return false;
	}
	pMessageDispatch->registerDBProxyHandler(EMODULE_ID_RANKINGLIST, this);
	pMessageDispatch->registerClientHandler(EMODULE_ID_RANKINGLIST, this);
	pMessageDispatch->registerServerHandler(EMODULE_ID_RANKINGLIST, this);

	g_GetActiveCharacterMgr()->AddCharacterObserver(this);

	//启定时器，每天5点
	//g_GetTimerAxis()->SetFixTimer((uint32_t)enRankingListTimeID::TIMER_ID_CHECK_UPDATE_DATA, 5*60*60, 1, this);

	
	g_GetTimerAxis()->SetTimer((uint32_t)enRankingListTimeID::TIMER_ID_UPDATE_SAVE, g_constUpDateSaveInterval,this);
	
	//向DB请求各排行版数据
	g_GetTimerAxis()->SetTimer((uint32_t)enRankingListTimeID::enSystemTimeID_RequestDB, 2*1000, this);


	g_GetTimerAxis()->SetTimer((uint32_t)enRankingListTimeID::TIMER_ID_CHEACK_OPERATR_ACTIVE, 60 * 1000, this);
	//注册事件
	//g_GetEvent()->Subscribe(this, EVENT_ATTR_CHANGE, 0, CREATURE_PLAYER,"RandLIst register chage attr");

	return true;
}
bool CRankingListMgr::UnInit()
{
	//MMO_DELETE(m_pLevelPool);
	//MMO_DELETE(m_pFightValuePool);
	//MMO_DELETE(m_pFightGoldPool);
	//MMO_DELETE(m_pFightDiamondPool);
	//MMO_DELETE(m_pKillPointPool);
	//g_GetEvent()->UnSubscribe(this, EVENT_ATTR_CHANGE, 0, CREATURE_PLAYER);


	g_GetActiveCharacterMgr()->RemoveCharacterObserver(this);

	g_GetTimerAxis()->KillAllTimer(this);
	g_GetTimerAxis()->KillAllFixTimer(this);
	return true;
}


void CRankingListMgr::DeleteOneCharacter(vecCharacterID & vList,CharIDType cid)
{
	//删除角色，把排行版中的该角色删除
	vecCharacterID::iterator iterLevel = vList.begin();
	for (; iterLevel != vList.end(); ++iterLevel)
	{
		if (iterLevel->_cid() == cid)
		{
			vList.erase(iterLevel);
			break;
		}
	}
}


void CRankingListMgr::onCharacterDel(OfflineCharacterData *pOffLineCharacter)
{
	//DeleteOneCharacter(m_vLevel, pOffLineCharacter->GetCharID());
	DeleteOneCharacter(m_vCurrentTimeLevel, pOffLineCharacter->GetCharID());
	//DeleteOneCharacter(m_vGold, pOffLineCharacter->GetCharID());
	//DeleteOneCharacter(m_vCurrentTimeGold, pOffLineCharacter->GetCharID());
	//DeleteOneCharacter(m_vDiamond, pOffLineCharacter->GetCharID());
	//DeleteOneCharacter(m_vCurrentTimeDiamond, pOffLineCharacter->GetCharID());

	DeleteOneCharacter(m_arrAllProFight, pOffLineCharacter->GetCharID());

	for (int i = 0; i < ECHARACTER_PROF_ARCHER;++i)
	{
		//DeleteOneCharacter(m_arrFightValue[i], pOffLineCharacter->GetCharID());
		DeleteOneCharacter(m_arrCurrentTimeFightValue[i], pOffLineCharacter->GetCharID());
	}

	for (int i = 0; i < ACHIEVEMENT_TYPE_ADVENTURE; ++i)
	{
	//	DeleteOneCharacter(m_arrAchievementPoint[i], pOffLineCharacter->GetCharID());
		DeleteOneCharacter(m_arrCurrentTimeAchievementPoint[i], pOffLineCharacter->GetCharID());
	}

	//m_bSaveFlag = true;
}

void 	CRankingListMgr::onCharacterLogin(ActiveCharacter *pOnlineCharacter)
{
	//登陆检测，如果有排名称号没发，则下发称号
	if ((int)m_vFightTitle.size() > 0)
	{
		for (std::vector<stRankNode>::iterator iter = m_vFightTitle.begin(); iter != m_vFightTitle.end(); ++iter)
		{
			if (iter->_cid() == pOnlineCharacter->GetCharID())
			{
				SendLogicServerRankingList(CenterToLogicRspRankingList::en_type_fight, iter->_cid(), iter->_value());
				m_vFightTitle.erase(iter);
				break;
			}
		}
	}

	if ((int)m_vLevelTitle.size()>0)
	{
		for (std::vector<stRankNode>::iterator iter = m_vLevelTitle.begin(); iter != m_vLevelTitle.end(); ++iter)
		{
			if (iter->_cid() == pOnlineCharacter->GetCharID())
			{
				SendLogicServerRankingList(CenterToLogicRspRankingList::en_type_level, iter->_cid(), iter->_value());
				m_vLevelTitle.erase(iter);
				break;
			}
		}
	}

	//更新几个排行
	//判断下请求的客户端等级够不够
	const FunctionunlockFunctionUnlockCfgInfo * pConfig = g_GetFunctionunlockFunctionUnlockCfgTable()->GetFunctionunlockFunctionUnlockCfgInfo(FunctionUnlock_ID_TYPE_RANKINGLIST);
	if (!pConfig)
	{
		return;
	}

	OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(pOnlineCharacter->GetCharID());
	if (!pCharacter)
	{
		return;
	}

	if (pCharacter->GetLevel() < pConfig->unlockLevel)
	{
		return;
	}

	stRankNode stNodeLevel;
	stNodeLevel.set__cid(pOnlineCharacter->GetCharID());
	stNodeLevel.set__value(pCharacter->GetLevel());
	SortRandListOneType(stNodeLevel, C_LEVEL, (ECharacterProf)pCharacter->GetProf(), ACHIEVEMENT_TYPE_NONE, pCharacter->GetExp());

	stRankNode stNodeFight;
	stNodeFight.set__cid(pOnlineCharacter->GetCharID());
	stNodeFight.set__value(pCharacter->GetFight());

	SortRandListOneType(stNodeFight, C_FIGHT_POWER, (ECharacterProf)pCharacter->GetProf());
	SortRandListOneType(stNodeFight, C_FIGHT_POWER, (ECharacterProf)0); //更新总战力排名


	
	std::string strClanName = "";
	std::string strLeadName = "";
	uint32_t canUseContribute = 0;
	uint32_t weekContribute = 0;
	g_GetUnionMgr()->GetUnionParamForRank(pCharacter->GetCharID(), strClanName, strLeadName, canUseContribute, weekContribute);
	if (!strClanName.empty())
	{
		//这里需要通知排行那边 历史共献改变
		RankingListClanContribute useContriChange;
		useContriChange.set_clanname(strClanName);
		useContriChange.set_contributevalue(pCharacter->GetHistoryContri());
		useContriChange.set_username(pCharacter->GetCharName());
		useContriChange.set_camp(pCharacter->GetCampID());
		ChangeClanContribute(useContriChange);


		//工会成员周贡献排行
		RankingListClanContribute tmpValue;
		tmpValue.set_clanname(strClanName);
		tmpValue.set_username(pCharacter->GetCharName());
		tmpValue.set_contributevalue(weekContribute);
		tmpValue.set_camp(pCharacter->GetCampID());
		ChangeClanWeekContribute(tmpValue);
	}
}



void        CRankingListMgr::onClientMessage(uint32_t actionId, RECV_PACKAGE& package, uint64_t Id)
{
	_UNUSE(Id);
	if (!IsRankDataLoad())
	{
		return;
	}
	switch (actionId)
	{
	case CLIENT_CENTER_REQUEST_RANKINGLIST:
		OnReqRankingListFromClient(package);
		break;
	case CLIENT_TO_LOGIC_RANDINGLIST_INDEX:
	{
		OnReqRandingListIndex(package);
	}
		break;
	default:
		break;
	}
}


void CRankingListMgr::SortRandListOneType(stRankNode & node, uint32_t type, ECharacterProf prof, AchievementType acivetype, uint32_t exp)
{
	vecCharacterID *tmpList=NULL;
	if (type == C_LEVEL)
	{
		tmpList = &m_vCurrentTimeLevel;
	}
	else if (type == C_FIGHT_POWER)
	{
		if (prof==0) //表示总战力
		{
			tmpList = &m_arrAllProFight;
		}
		else
		{
			tmpList = &m_arrCurrentTimeFightValue[prof - 1];
		}
		
	}
	else if (type == C_GOLD)
	{
		//tmpList = &m_vCurrentTimeGold;
	}
	else if (type == C_DIAMOND)
	{
		//tmpList = &m_vCurrentTimeDiamond;
	}
	else 
	{
		if (acivetype >ACHIEVEMENT_TYPE_NONE && acivetype <ACHIEVEMENT_TYPE_NUM )
		{
			tmpList = &m_arrCurrentTimeAchievementPoint[acivetype-1];
		}
	}

	if (tmpList==NULL)
	{
		return;
	}



	vecCharacterID::iterator iter = tmpList->begin();
	for (; iter != tmpList->end();++iter)
	{
		if (iter->_cid() == node._cid() )
		{
			//iter->set__value(node._value());
			//std::sort(tmpList->begin(), tmpList->end(), CmpCharacterLevel);
			//stRankNode tmpNode = *iter;

			//一样的，不需要处理
			if (iter->_value()==node._value())
			{
				return;
			}

			tmpList->erase(iter);
			tmpList->push_back(node);
			SortV(*tmpList, exp,false);
			return;
		}
	}

	if ((uint32_t)tmpList->size() < g_constRankingListCount)
	{
		tmpList->push_back(node);
		SortV(*tmpList, exp,false);
	}
	else
	{
		if ((*tmpList)[tmpList->size()-1]._value()<=node._value())
		{
			//tmpList->push_back(node);
			//std::sort(tmpList->begin(), tmpList->end(),CmpCharacterLevel);
			tmpList->push_back(node);
			SortV(*tmpList, exp,false);
			tmpList->erase(tmpList->end() - 1);
		}
	}
}

void CRankingListMgr::onCharacterUpdate(ActiveCharacter *pOnlineCharacter)
{
	//判断下请求的客户端等级够不够
	const FunctionunlockFunctionUnlockCfgInfo * pConfig = g_GetFunctionunlockFunctionUnlockCfgTable()->GetFunctionunlockFunctionUnlockCfgInfo(FunctionUnlock_ID_TYPE_RANKINGLIST);
	if (!pConfig)
	{
		return;
	}

	OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(pOnlineCharacter->GetCharID());
	if (!pCharacter)
	{
		return;
	}

	if (pCharacter->GetLevel() < pConfig->unlockLevel)
	{
		//LogDebugFmtPrint(" CRankingListMgr open level is not enough level=%d", pCharacterCurrent->GetLevel());
		return;
	}

	if (pOnlineCharacter->GetLastAttrUpdate(C_LEVEL) > 0)
	{
	
		stRankNode stNode;
		stNode.set__cid(pOnlineCharacter->GetCharID());
		stNode.set__value(pCharacter->GetLevel());

		SortRandListOneType(stNode, C_LEVEL, (ECharacterProf)pCharacter->GetProf(), ACHIEVEMENT_TYPE_NONE, pCharacter->GetExp());
		m_bSaveFlag = true;
	}	
	if (pOnlineCharacter->GetLastAttrUpdate(C_FIGHT_POWER)>0)
	{
		stRankNode stNode;
		stNode.set__cid(pOnlineCharacter->GetCharID());
		stNode.set__value(pCharacter->GetFight());

		SortRandListOneType(stNode, C_FIGHT_POWER, (ECharacterProf)pCharacter->GetProf());
		SortRandListOneType(stNode, C_FIGHT_POWER, (ECharacterProf)0); //更新总战力排名
		m_bSaveFlag = true;
	}

	//if (pOnlineCharacter->GetLastAttrUpdate(C_EXP)>0)
	//{

	//	stRankNode stNode;
	//	stNode.set__cid(pOnlineCharacter->GetCharID());
	//	stNode.set__value(pCharacter->GetLevel());

	//	SortRandListOneType(stNode, C_LEVEL, (ECharacterProf)pCharacter->GetProf(), ACHIEVEMENT_TYPE_NONE, pCharacter->GetExp());
	//	m_bSaveFlag = true;
	//}

	// if (pOnlineCharacter->GetLastAttrUpdate(C_GOLD)>0)
	//{

	//	OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(pOnlineCharacter->GetCharID());
	//	if (!pCharacter)
	//	{
	//		return;
	//	}

	//	stRankNode stNode;
	//	stNode.set__cid(pOnlineCharacter->GetCharID());
	//	stNode.set__value(pCharacter->GetGold());

	//	SortRandListOneType(stNode, C_GOLD, (ECharacterProf)pCharacter->GetProf());
	//	m_bSaveFlag = true;
	//}
	//if (pOnlineCharacter->GetLastAttrUpdate(C_DIAMOND)>0)
	//{
	//	OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(pOnlineCharacter->GetCharID());
	//	if (!pCharacter)
	//	{
	//		return;
	//	}

	//	stRankNode stNode;
	//	stNode.set__cid(pOnlineCharacter->GetCharID());
	//	stNode.set__value(pCharacter->GetDiamond());

	//	SortRandListOneType(stNode, C_DIAMOND, (ECharacterProf)pCharacter->GetProf());
	//	m_bSaveFlag = true;
	//}
}


void CRankingListMgr::OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen)
{
	//if (nEventID == EVENT_ATTR_CHANGE)
	//{
	//	//记录最新的前100名玩家属性
	//	AttrChangeEvent  *pChangeInfo = static_cast<AttrChangeEvent  *>(pContext);
	//	if (pChangeInfo)
	//	{
	//		OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(pChangeInfo->changeCid);
	//		if (!pCharacter)
	//		{
	//			return;
	//		}

	//		for (int32_t i = 0; i < (int32_t)pChangeInfo->vAttr.size(); i++)
	//		{
	//			stRankNode stNode;
	//			stNode.set__cid(pChangeInfo->changeCid);
	//			stNode.set__value(pChangeInfo->vAttr[i]->attrValue);

	//			SortRandListOneType(stNode, pChangeInfo->vAttr[i]->attrNum, (ECharacterProf)pCharacter->GetProf());


	//			delete pChangeInfo->vAttr[i];
	//		}

	//		m_bSaveFlag = true;
	//	}
	//}
}

//----客户端消息
void CRankingListMgr::OnReqRankingListFromClient(RECV_PACKAGE &package)
{
	RankingListReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecUpdateAchiementFromLogic return but parse failed....");
		return;
	}

	//返回消息
	RankingListRsp rsp;
	rsp.set_type(req.type());

	//判断下请求的客户端等级够不够
	const FunctionunlockFunctionUnlockCfgInfo * pConfig=g_GetFunctionunlockFunctionUnlockCfgTable()->GetFunctionunlockFunctionUnlockCfgInfo(FunctionUnlock_ID_TYPE_RANKINGLIST);
	if (!pConfig)
	{
		return;
	}

	OfflineCharacterData * pCharacterCurrent = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(req.cid());
	if (!pCharacterCurrent || pCharacterCurrent->GetLevel() < pConfig->unlockLevel)
	{
		//LogDebugFmtPrint(" CRankingListMgr open level is not enough level=%d", pCharacterCurrent->GetLevel());
		return;
	}

	if (req.type() == enRankingListType::enRankingListType_Level)
	{
		OnReqLevelRankList(req.cid(),rsp);
	}
	else if (req.type() >= enRankingListType::enRankingListType_WarriorFight && req.type() <= enRankingListType::enRankingListType_ArcgerFight)
	{
		OnReqFightRankList(req.cid(), rsp, req.type());
	}
	else if (req.type() == enRankingListType::enRankingListType_AllFight)
	{
		OnReqAllProRankList(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_AllKillPoint)
	{
		OnReqAllKillPoint(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_LightKillPoint)
	{
		OnReqLightKillPoint(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_BlackKillPoint)
	{
		OnReqBlackKillPoint(req.cid(), rsp);
	}
	else if (req.type() >= enRankingListType::enRankingListType_achievement_person && req.type() <= enRankingListType::enRankingListType_achievement_general)
	{
		OnReqAchievementRandList(req.cid(), rsp,req.type());
	}
	else if (req.type() == enRankingListType::enRankingListType_AllPrestige)
	{
		OnReqAllPristige(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_LightPrestige)
	{
		OnReqLightPristige(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_BlackPrestige)
	{
		OnReqBlackPristige(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_Arena)
	{
		OnReqArenaRankingList(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_ClanFight)
	{
		OnReqClanFightRankingList(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_Clan_Contribute)
	{
		OnReqClanCanUseContributeRankingList(req.cid(), rsp);
	}
	else if (req.type() == enRankingListType::enRankingListType_Clan_Week_Contribute)
	{
		OnReqClanWeekContributeRankingList(req.cid(), rsp);
	}
	else
	{
		rsp.set_levelrank(0);
	}

	g_GetCenterService()->SendDataToClient(req.cid(), (uint16_t)EMODULE_ID_RANKINGLIST,(uint16_t)CENTER_TO_CLIENT_RANKINGLIST_RESULT ,&rsp);
}

//客户端请求玩家排名
void CRankingListMgr::OnReqRandingListIndex(RECV_PACKAGE &package)
{
	PlayerRankingListIndexReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecUpdateAchiementFromLogic return but parse failed....");
		return;
	}

	NoticPlayerRankingListIndexRsp rsp;

	rsp.set_level(1000);
	rsp.set_fight(1000);

	for (int i = 0; i < (int)m_vCurrentTimeLevel.size();++i)
	{
		if (m_vCurrentTimeLevel[i]._cid()== req.cid())
		{
			rsp.set_level(i+1);
		}
	}

	for (int i = 0; i < (int)m_arrAllProFight.size();++i)
	{
		if (m_arrAllProFight[i]._cid() == req.cid())
		{
			rsp.set_fight(i+1);
		}
	}

	g_GetCenterService()->SendDataToClient(req.cid(), (uint16_t)EMODULE_ID_RANKINGLIST, (uint16_t)LOGIC_TO_CLIENT_RANKINGLIST_INDEX, &rsp);
}

void		CRankingListMgr::onServerMessage(uint32_t actionId, RECV_PACKAGE &package)
{
	switch (actionId)
	{
	case LOGIC_CENTER_UPDATe_RANKING_LIST_ACHIEVEMENT:
		OnRecUpdateAchiementFromLogic(package);
		break;
	default:
		break;
	}

	return;
	
}

void CRankingListMgr::OnRecUpdateAchiementFromLogic(RECV_PACKAGE &package) //更新成就积分
{
	LogicToCenterRankingListAchievement rsp;
	if (!rsp.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[center] OnRecUpdateAchiementFromLogic return but parse failed....");
		return;
	}

	//修改数据
	OfflineCharacterData * pCharacter=g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(rsp.charid());
	if (pCharacter)
	{

		pCharacter->SetAchievementPoint((AchievementType)rsp.changeachievement().type(), rsp.changeachievement().point());

		//判断下请求的客户端等级够不够
		const FunctionunlockFunctionUnlockCfgInfo * pConfig = g_GetFunctionunlockFunctionUnlockCfgTable()->GetFunctionunlockFunctionUnlockCfgInfo(FunctionUnlock_ID_TYPE_RANKINGLIST);
		if (!pConfig)
		{
			return;
		}

		if (pCharacter->GetLevel() < pConfig->unlockLevel)
		{
			//LogDebugFmtPrint(" CRankingListMgr open level is not enough level=%d", pCharacterCurrent->GetLevel());
			return;
		}

		//for (int i = 0; i < rsp.changeachievementlist_size();++i)
		//{
		//	stRankNode stNode;
		//	stNode.set__cid(rsp.charid());
		//	stNode.set__value(rsp.changeachievementlist(i).point());
		//	SortRandListOneType(stNode, 0, (ECharacterProf)pCharacter->GetProf(), (AchievementType)rsp.changeachievementlist(i).type());
		////	pCharacter->SetAchievementPoint((AchievementType)rsp.changeachievementlist(i).type(), rsp.changeachievementlist(i).completecount());
		//}
		stRankNode stNode;
		stNode.set__cid(rsp.charid());
		stNode.set__value(rsp.changeachievement().point());
		SortRandListOneType(stNode, 0, (ECharacterProf)pCharacter->GetProf(), (AchievementType)rsp.changeachievement().type());

		
	}
}


bool CRankingListMgr::SaveDB(uint64_t freshTime)
{
	if (!IsRankDataLoad())
	{
		return false;
	}

	GlobalDBSetRequest req;
	req.set_type_id(EGlobalType_RankingList);
	//填数据
	RankingListData stData;
	stRankNode * pNode = NULL;
	stData.set_freshtime(freshTime);

	
	for (int i = 0; i < (int)m_vCurrentTimeLevel.size(); ++i)
	{
		pNode = stData.add_currenttimelevelid();
		if (pNode)
		{
			pNode->CopyFrom(m_vCurrentTimeLevel[i]);
		}
		
	}

	//职业战斗力排行
	for (int i = 0; i < ECHARACTER_PROF_ARCHER; ++i)
	{
		for (int j = 0; j < (int)m_arrCurrentTimeFightValue[i].size(); ++j)
		{
			if (i == 0)
			{
				pNode = stData.add_currenttimefightidprof1();
			}
			else if (i == 1)
			{
				pNode = stData.add_currenttimefightidprof2();
			}
			else if (i == 2)
			{
				pNode = stData.add_currenttimefightidprof3();
			}
			else if (i == 3)
			{
				pNode = stData.add_currenttimefightidprof4();

			}
			if (pNode)
			{
				pNode->CopyFrom(m_arrCurrentTimeFightValue[i][j]);
			}
		}

		//作个错误打印吧，现在应该是不会操过
		if ((uint32_t)m_arrCurrentTimeFightValue[i].size() > g_constRankingListCount)
		{
			LogErrFmtPrint("current arrfightvalue i=%d over range size=%d", i, m_arrCurrentTimeFightValue[i].size());
		}
	}

	stData.set_operateactivefightreward(m_bOperateActiveFightReword);
	stData.set_operateactivelevelreward(m_bOperateActiveLevelReword);


	for (int i = 0; i < (int)m_vFightTitle.size(); ++i)
	{
		pNode = stData.add_fighttitleinfo();
		if (pNode)
		{
			pNode->CopyFrom(m_vFightTitle[i]);
		}
		
	}

	for (int i = 0; i < (int)m_vLevelTitle.size(); ++i)
	{
		pNode = stData.add_leveltitleinfo();
		if (pNode)
		{
			pNode->CopyFrom(m_vLevelTitle[i]);
		}
	}


	string strMall = stData.SerializeAsString();
	req.set_data(strMall);

	if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_SAVE_REQ, &req))
	{
		LogErrFmtPrint("[center] SaveRandingListDataReq.....SendDataToDBProxy faild...");
		return false;
	}


	SaveDBUnion(freshTime);
	SaveDBCamp(freshTime);
	SaveDBAchievement(freshTime);

	return true;

}

bool CRankingListMgr::SaveDBUnion(uint64_t freshTime)
{
	GlobalDBSetRequest req;
	req.set_type_id(EGlobalType_RankingList1);
	//填数据
	RankingListData stData;
	//stRankNode * pNode = NULL;
	stData.set_freshtime(freshTime);


	//可用贡献版
	for (int i = 0; i < (int)m_vClanCurrentTimeContribute.size(); ++i)
	{
		RankingListClanContribute * pdata = stData.add_canusecurrentcontribute();
		if (pdata)
		{
			*pdata = m_vClanCurrentTimeContribute[i];
		}
		
	}
	//周贡献版
	for (int i = 0; i < (int)m_vClanCurrentTimeWeekContribute.size(); ++i)
	{
		RankingListClanContribute * pdata = stData.add_weekcurrentcontribute();
		if (pdata)
		{
			*pdata = m_vClanCurrentTimeWeekContribute[i];
		}
	}


	string strMall = stData.SerializeAsString();
	req.set_data(strMall);

	if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_SAVE_REQ, &req))
	{
		LogErrFmtPrint("[center] SaveRandingListDataReq.....SendDataToDBProxy faild...");
		return false;
	}

	return true;

}
bool CRankingListMgr::SaveDBCamp(uint64_t freshTime)
{
	GlobalDBSetRequest req;
	req.set_type_id(EGlobalType_RankingList2);
	//填数据
	RankingListData stData;
	//stRankNode * pNode = NULL;
	stData.set_freshtime(freshTime);
	//综合击杀版
	for (int i = 0; i < (int)m_vAllKill.size(); ++i)
	{
		RankingListKillPoingData * pdata = stData.add_allkillpoint();
		if (pdata)
		{
			*pdata = m_vAllKill[i];
		}
		
	}
	//光明击杀
	for (int i = 0; i < (int)m_vLightKill.size(); ++i)
	{
		RankingListKillPoingData * pdata = stData.add_lightkillpoint();
		if (pdata)
		{
			*pdata = m_vLightKill[i];
		}
		
	}

	//黑暗击杀
	for (int i = 0; i < (int)m_vBlackKill.size(); ++i)
	{
		RankingListKillPoingData * pdata = stData.add_blackkillpoint();
		if (pdata)
		{
			*pdata = m_vBlackKill[i];
		}
		
	}


	//综合声望
	for (int i = 0; i < (int)m_vAllPristige.size(); ++i)
	{
		RankingListKillPoingData * pdata = stData.add_allpristige();
		if (pdata)
		{
			*pdata = m_vAllPristige[i];
		}
		
	}
	//光明声望
	for (int i = 0; i < (int)m_vLightPristige.size(); ++i)
	{
		RankingListKillPoingData * pdata = stData.add_lightpristige();
		if (pdata)
		{
			*pdata = m_vLightPristige[i];
		}
		
	}

	//黑暗声望
	for (int i = 0; i < (int)m_vBlackPristige.size(); ++i)
	{
		RankingListKillPoingData * pdata = stData.add_blackpristige();
		if (pdata)
		{
			*pdata = m_vBlackPristige[i];
		}
		
	}

	string strMall = stData.SerializeAsString();
	req.set_data(strMall);

	if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_SAVE_REQ, &req))
	{
		LogErrFmtPrint("[center] SaveRandingListDataReq.....SendDataToDBProxy faild...");
		return false;
	}

	return true;

}

bool CRankingListMgr::SaveDBAchievement(uint64_t freshTime)
{
	GlobalDBSetRequest req;
	req.set_type_id(EGlobalType_RankingList3);
	//填数据
	RankingListData stData;
	stRankNode * pNode = NULL;
	stData.set_freshtime(freshTime);

	//成就
	//for (int i = 0; i < ACHIEVEMENT_TYPE_ADVENTURE; ++i)
	//{
	//	for (int j = 0; j < (int)m_arrAchievementPoint[i].size(); ++j)
	//	{
	//		if (i == 0)
	//		{
	//			pNode = stData.add_achivepoint1();
	//		}
	//		else if (i == 1)
	//		{
	//			pNode = stData.add_achivepoint2();

	//		}
	//		else if (i == 2)
	//		{
	//			pNode = stData.add_achivepoint3();
	//		}
	//		else if (i == 3)
	//		{
	//			pNode = stData.add_achivepoint4();
	//		}
	//		else if (i == 4)
	//		{
	//			pNode = stData.add_achivepoint5();
	//		}

	//		pNode->CopyFrom(m_arrAchievementPoint[i][j]);
	//	}
	//}

	//成就
	for (int i = 0; i < ACHIEVEMENT_TYPE_ADVENTURE; ++i)
	{
		for (int j = 0; j < (int)m_arrCurrentTimeAchievementPoint[i].size(); ++j)
		{
			if (i == 0)
			{
				pNode = stData.add_currenttimeachivepoint1();
			}
			else if (i == 1)
			{
				pNode = stData.add_currenttimeachivepoint2();
			}
			else if (i == 2)
			{
				pNode = stData.add_currenttimeachivepoint3();
			}
			else if (i == 3)
			{
				pNode = stData.add_currenttimeachivepoint4();
			}
			else if (i == 4)
			{
				pNode = stData.add_currenttimeachivepoint5();
			}
			if (pNode)
			{
				pNode->CopyFrom(m_arrCurrentTimeAchievementPoint[i][j]);
			}
			
		}
	}

	string strMall = stData.SerializeAsString();
	req.set_data(strMall);

	if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_SAVE_REQ, &req))
	{
		LogErrFmtPrint("[center] SaveRandingListDataReq.....SendDataToDBProxy faild...");
		return false;
	}

	return true;
}





bool CRankingListMgr::LoadDB(const string &data)
{

	if (data.length() > 0)
	{
		RankingListData stRankingListData;
		if (!stRankingListData.ParseFromArray(data.c_str(), (int32_t)data.length()))
		{
			MMOLOG_FMT_ERROR("[center] LoadRankingListDataRet parase failed...");
			return false;
		}

		//m_i64FreshTime = stRankingListData.freshtime();

		////等级
		for (int i = 0; i < (int)stRankingListData.currenttimelevelid_size(); ++i)
		{
			m_vCurrentTimeLevel.push_back(stRankingListData.currenttimelevelid(i));
		}

		SortV(m_vCurrentTimeLevel, 1, true);

		//职业战斗力
		for (int i = 0; i < (int)stRankingListData.currenttimefightidprof1_size(); ++i)
		{
			stRankNode node = stRankingListData.currenttimefightidprof1(i);
			//m_arrCurrentTimeFightValue[0].push_back(node);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)1);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)0);  //总战力
		}

		for (int i = 0; i < (int)stRankingListData.currenttimefightidprof2_size(); ++i)
		{
			stRankNode node = stRankingListData.currenttimefightidprof2(i);
			//m_arrCurrentTimeFightValue[1].push_back(node);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)2);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)0);  //总战力
		}

		for (int i = 0; i < (int)stRankingListData.currenttimefightidprof3_size(); ++i)
		{
			stRankNode node = stRankingListData.currenttimefightidprof3(i);
			//m_arrCurrentTimeFightValue[2].push_back(node);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)3);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)0);  //总战力
		}

		for (int i = 0; i < (int)stRankingListData.currenttimefightidprof4_size(); ++i)
		{
			stRankNode node = stRankingListData.currenttimefightidprof4(i);
			//m_arrCurrentTimeFightValue[3].push_back(node);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)4);
			SortRandListOneType(node, C_FIGHT_POWER, (ECharacterProf)0);  //总战力
		}

		m_bOperateActiveFightReword = stRankingListData.operateactivefightreward();
		m_bOperateActiveLevelReword = stRankingListData.operateactivelevelreward();

		for (int i = 0; i < (int)stRankingListData.fighttitleinfo_size(); ++i)
		{
			m_vFightTitle.push_back(stRankingListData.fighttitleinfo(i));
		}

		for (int i = 0; i < (int)stRankingListData.leveltitleinfo_size(); ++i)
		{
			m_vLevelTitle.push_back(stRankingListData.leveltitleinfo(i));
		}
	
	}

	LogDebugFmtPrint("load rankinglist person data finish  datesize=%d", data.length());

	return true;
}


bool CRankingListMgr::LoadDBUnion(const string &data)
{
	if (data.length() > 0)
	{
		RankingListData stRankingListData;
		if (!stRankingListData.ParseFromArray(data.c_str(), (int32_t)data.length()))
		{
			MMOLOG_FMT_ERROR("[center] LoadRankingListDataRet parase failed...");
			return false;
		}
		//m_i64FreshTime = stRankingListData.freshtime();
		//可用贡献
		for (int i = 0; i < (int)stRankingListData.canusecurrentcontribute_size(); ++i)
		{

			RankingListClanContribute tmpData = stRankingListData.canusecurrentcontribute(i);
			ChangeClanContribute(tmpData);

			//m_vClanCurrentTimeContribute.push_back(stRankingListData.canusecurrentcontribute(i));
		}

		//周贡献
		for (int i = 0; i < (int)stRankingListData.weekcurrentcontribute_size(); ++i)
		{
			RankingListClanContribute tmpData = stRankingListData.weekcurrentcontribute(i);


			ChangeClanWeekContribute(tmpData);
			//m_vClanCurrentTimeWeekContribute.push_back(stRankingListData.weekcurrentcontribute(i));
		}

		//Date nowDate = Time::GetLocalDate();
		//Date freshDate = Time::GetLocalDate(m_i64FreshTime);
		
	}

	LogDebugFmtPrint("load rankinglist  clan data finish  datesize=%d", data.length());

	return true;
}
bool CRankingListMgr::LoadDBCamp(const string &data)
{
	if (data.length() > 0)
	{
		RankingListData stRankingListData;
		if (!stRankingListData.ParseFromArray(data.c_str(), (int32_t)data.length()))
		{
			MMOLOG_FMT_ERROR("[center] LoadRankingListDataRet parase failed...");
			return false;
		}

		//m_i64FreshTime = stRankingListData.freshtime();
		//综合击杀
		for (int i = 0; i < (int)stRankingListData.allkillpoint_size(); ++i)
		{
			m_vAllKill.push_back(stRankingListData.allkillpoint(i));
		}

		//光明击杀
		for (int i = 0; i < (int)stRankingListData.lightkillpoint_size(); ++i)
		{
			m_vLightKill.push_back(stRankingListData.lightkillpoint(i));
		}

		//黑暗击杀
		for (int i = 0; i < (int)stRankingListData.blackkillpoint_size(); ++i)
		{
			m_vBlackKill.push_back(stRankingListData.blackkillpoint(i));
		}

		//综合声望
		for (int i = 0; i < (int)stRankingListData.allpristige_size(); ++i)
		{
			m_vAllPristige.push_back(stRankingListData.allpristige(i));
		}

		//光明声望 
		for (int i = 0; i < (int)stRankingListData.lightpristige_size(); ++i)
		{
			m_vLightPristige.push_back(stRankingListData.lightpristige(i));
		}

		//黑暗声望
		for (int i = 0; i < (int)stRankingListData.blackpristige_size(); ++i)
		{
			m_vBlackPristige.push_back(stRankingListData.blackpristige(i));
		}

		//Date nowDate = Time::GetLocalDate();
		//Date freshDate = Time::GetLocalDate(m_i64FreshTime);

		GetPrestige();
		GetKillPointRandList();
	}

	LogDebugFmtPrint("load rankinglist  camp data finish  datesize=%d", data.length());

	return true;
}
bool CRankingListMgr::LoadDBAchievement(const string &data)
{
	if (data.length() > 0)
	{
		RankingListData stRankingListData;
		if (!stRankingListData.ParseFromArray(data.c_str(), (int32_t)data.length()))
		{
			MMOLOG_FMT_ERROR("[center] LoadRankingListDataRet parase failed...");
			return false;
		}

		//m_i64FreshTime = stRankingListData.freshtime();

		//成就
		for (int i = 0; i < (int)stRankingListData.currenttimeachivepoint1_size(); ++i)
		{
			m_arrCurrentTimeAchievementPoint[0].push_back(stRankingListData.currenttimeachivepoint1(i));
		}
		SortV(m_arrCurrentTimeAchievementPoint[0], 0, true);
		//成就
		for (int i = 0; i < (int)stRankingListData.currenttimeachivepoint2_size(); ++i)
		{
			m_arrCurrentTimeAchievementPoint[1].push_back(stRankingListData.currenttimeachivepoint2(i));
		}
		SortV(m_arrCurrentTimeAchievementPoint[1], 0, true);
		//成就
		for (int i = 0; i < (int)stRankingListData.currenttimeachivepoint3_size(); ++i)
		{
			m_arrCurrentTimeAchievementPoint[2].push_back(stRankingListData.currenttimeachivepoint3(i));
		}
		SortV(m_arrCurrentTimeAchievementPoint[2], 0, true);
		//成就
		for (int i = 0; i < (int)stRankingListData.currenttimeachivepoint4_size(); ++i)
		{
			m_arrCurrentTimeAchievementPoint[3].push_back(stRankingListData.currenttimeachivepoint4(i));
		}
		SortV(m_arrCurrentTimeAchievementPoint[3], 0, true);
		//成就
		for (int i = 0; i < (int)stRankingListData.currenttimeachivepoint5_size(); ++i)
		{
			m_arrCurrentTimeAchievementPoint[4].push_back(stRankingListData.currenttimeachivepoint5(i));
		}
		SortV(m_arrCurrentTimeAchievementPoint[4], 0, true);

		//Date nowDate = Time::GetLocalDate();
		//Date freshDate = Time::GetLocalDate(m_i64FreshTime);

		//if (nowDate.yday != freshDate.yday) //是同一天，不用刷，否则需要补刷
		{
			GetAchievementRandList();
		}
	}

	m_bLoadFlag = true;
	LogDebugFmtPrint("load rankinglist Achievement data finish  datesize=%d", data.length());

	return true;
}



void CRankingListMgr::NoticeRefreshKillPoint(std::vector<RankingListKillPoingData > & v, enRankingListType type)
{
	if (enRankingListType::enRankingListType_AllKillPoint == type)
	{
		m_vAllKill.clear();
		for (int i = 0; i < (int)v.size();++i)
		{
			m_vAllKill.push_back(v[i]);
		}
	}
	else if (enRankingListType::enRankingListType_LightKillPoint == type)
	{
		m_vLightKill.clear();
		for (int i = 0; i < (int)v.size(); ++i)
		{
			m_vLightKill.push_back(v[i]);
		}
	}
	else if (enRankingListType::enRankingListType_BlackKillPoint == type)
	{
		m_vBlackKill.clear();
		for (int i = 0; i < (int)v.size(); ++i)
		{
			m_vBlackKill.push_back(v[i]);
		}
	}

}


void CRankingListMgr::DailyUpdate()
{
	// GetLevelRankList();
	// GetFightRankList();
	// GetGoldRankList();
	// GetDiamondRandList();
	// GetAchievementRandList();
	
		 GetPrestige();
		 GetKillPointRandList();
		 GetArenaRankingList();
		 //GetClanCanUseContriubte();
		// GetClanWeekContribute();
		 GetClanRankignList();
		 //SaveDB(Time::Now().UnixSec());
	
}

void CRankingListMgr::DailyZeroUpdate()
{
	//这里将活动发放奖励标记还原，以便下次再进行活动判断。
	//m_bOperateActiveFightReword = false;
	//m_bOperateActiveLevelReword = false;
	CheckOperateActive();
}

void CRankingListMgr::OnTimer(uint32_t nTimerID)
{
	if (nTimerID == (uint32_t)enRankingListTimeID::TIMER_ID_CHECK_UPDATE_DATA)
	{
		DailyUpdate();
	}
	else if (nTimerID ==  (uint32_t)enRankingListTimeID::TIMER_ID_UPDATE_SAVE)
	{
		if (m_bSaveFlag)
		{
			SaveDB(m_i64FreshTime);
			m_bSaveFlag = false;
		}
	}
	else if (nTimerID == (uint32_t)enRankingListTimeID::enSystemTimeID_RequestDB)
	{
		if (g_GetCenterService()->IsConnectDBProxy() && g_GetOfflineCharacterDataMgr()->IsFinishLoad() && g_GetUnionMgr()->IsFinishLoad())
		{
			GlobalDBRequst req;
			req.set_type_id(EGlobalType_RankingList);

			if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_GET_REQ, &req))
			{
				LogErrFmtPrint("[center] CRankingListMgr::request load randkinglist data...SendDataToDBProxy failed...");
			}
			else
			{
				LogDebugFmtPrint("[center] CRankingListMgr::request start load randkinglist data.....");
			}


			req.set_type_id(EGlobalType_RankingList1);

			if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_GET_REQ, &req))
			{
				LogErrFmtPrint("[center] CRankingListMgr::request load randkinglist union data...SendDataToDBProxy failed...");
			}
			else
			{
				LogDebugFmtPrint("[center] CRankingListMgr::request start load randkinglist union data.....");
			}


			req.set_type_id(EGlobalType_RankingList2);

			if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_GET_REQ, &req))
			{
				LogErrFmtPrint("[center] CRankingListMgr::request load randkinglist camp data...SendDataToDBProxy failed...");
			}
			else
			{
				LogDebugFmtPrint("[center] CRankingListMgr::request start load randkinglist camp data.....");
			}


			req.set_type_id(EGlobalType_RankingList3);

			if (!g_GetCenterService()->SendDataToDBProxy(EMODULE_ID_SERV_SYS, DBPROXY_PROTOCOL_GLOBAL_GET_REQ, &req))
			{
				LogErrFmtPrint("[center] CRankingListMgr::request load randkinglist achivement data...SendDataToDBProxy failed...");
			}
			else
			{
				LogDebugFmtPrint("[center] CRankingListMgr::request start load randkinglist achivement data.....");
			}





			g_GetTimerAxis()->KillTimer((uint32_t)enRankingListTimeID::enSystemTimeID_RequestDB,this);

			return ;
		}
		
	}
	else if (nTimerID == (uint32_t)enRankingListTimeID::TIMER_ID_CHEACK_OPERATR_ACTIVE)
	{
		//判断是否需要补发运营活动奖励
		if (IsRankDataLoad())
		{
			CheckOperateActive(false);
			g_GetTimerAxis()->KillTimer((uint32_t)enRankingListTimeID::TIMER_ID_CHEACK_OPERATR_ACTIVE, this);
		}
	}
}


void CRankingListMgr::GetLevelRankList()
{
	//m_vLevel.clear();

	//for (int i = 0; i < (int)m_vCurrentTimeLevel.size();++i)
	//{
	//	m_vLevel.push_back(m_vCurrentTimeLevel[i]);
	//}
}

void CRankingListMgr::GetFightRankList()
{
	//for (int i = 0; i < ECHARACTER_PROF_ARCHER;++i)
	//{
	//	m_arrFightValue[i].clear();
	//	//for (int j = 0; j < (int)m_arrCurrentTimeFightValue[i].size(); ++j)
	//	//{
	//	//	m_arrFightValue[i].push_back(m_arrCurrentTimeFightValue[i][j]);
	//	//}
	//	m_arrFightValue[i].insert(m_arrFightValue[i].begin(), m_arrCurrentTimeFightValue[i].begin(), m_arrCurrentTimeFightValue[i].end());
	//}
}


void CRankingListMgr::GetGoldRankList()
{
	//m_vGold.clear();
	//for (int i = 0; i < (int)m_vCurrentTimeGold.size();++i)
	//{
	//	m_vGold.push_back(m_vCurrentTimeGold[i]);
	//}
}

void CRankingListMgr::GetKillPointRandList()
{
	
	GetAllKillPointRandList();
	GetLightKillPointRandList();
	GetBlackkillPointRandList();
}


void CRankingListMgr::GetAllKillPointRandList()
{
	m_vAllKill.clear();
	g_GetCampMgr()->GetCampRank(m_vAllKill, 100, enRankingListType::enRankingListType_AllKillPoint);
}
void CRankingListMgr::GetLightKillPointRandList()
{
	m_vLightKill.clear();
	g_GetCampMgr()->GetCampRank(m_vLightKill, 100, enRankingListType::enRankingListType_LightKillPoint);
}
void CRankingListMgr::GetBlackkillPointRandList()
{
	m_vBlackKill.clear();
	g_GetCampMgr()->GetCampRank(m_vBlackKill, 100, enRankingListType::enRankingListType_BlackKillPoint);
}

void CRankingListMgr::GetAllPrestige()  //获取声望
{
	GetLigthPrestige();
	GetBlackPrestige();
	GetPrestige();
}
void CRankingListMgr::GetLigthPrestige()
{
	m_vLightPristige.clear();
	g_GetCampMgr()->GetCampRank(m_vLightPristige, 100, enRankingListType::enRankingListType_LightPrestige);
}
void CRankingListMgr::GetBlackPrestige()
{
	m_vBlackPristige.clear();
	g_GetCampMgr()->GetCampRank(m_vBlackPristige, 100, enRankingListType::enRankingListType_BlackPrestige);
}
void CRankingListMgr::GetPrestige()
{
	m_vAllPristige.clear();
	g_GetCampMgr()->GetCampRank(m_vAllPristige, 100, enRankingListType::enRankingListType_AllPrestige);
}


void CRankingListMgr::GetArenaRankingList()
{
	m_vArenaRankInfo.clear();
	g_GetArenaMgr()->GetArenaRankList(m_vArenaRankInfo);
}


void CRankingListMgr::GetDiamondRandList()
{
	//m_vDiamond.clear();
	//for (int i = 0; i < (int)m_vCurrentTimeDiamond.size();++i)
	//{
	//	m_vDiamond.push_back(m_vCurrentTimeDiamond[i]);
	//}
}

void CRankingListMgr::GetAchievementRandList()
{
	//for (int i = 0; i < ACHIEVEMENT_TYPE_ADVENTURE;++i)
	//{
	//	m_arrAchievementPoint[i].clear();
	//	for (int j = 0; j < (int)m_arrCurrentTimeAchievementPoint[i].size();++j)
	//	{
	//		m_arrAchievementPoint[i].push_back(m_arrCurrentTimeAchievementPoint[i][j]);
	//	}
	//}
}

void CRankingListMgr::OnReqLevelRankList(CharIDType currentCid, RankingListRsp & rsp)
{
	
	//if ((uint32_t)m_vLevel.size()<g_constRankingListCount)
	//{
	//	GetLevelRankList();
	//}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListLevelData * pData = rsp.add_levelist();
	pData->set_cid(currentCid);
	OfflineCharacterData * pCharacterCurrent = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (pCharacterCurrent)
	{

		pData->set_level(pCharacterCurrent->GetLevel());
		pData->set_prof(pCharacterCurrent->GetProf());
		pData->set_username(pCharacterCurrent->GetCharName());
		pData->set_camp(pCharacterCurrent->GetCampID());
	}

	int minCount = 0;
	int maxCount = g_constRankingListCount;
	vecCharacterID::iterator iter = m_vCurrentTimeLevel.begin();
	for (; iter != m_vCurrentTimeLevel.end(); )
	{
		if (tmpIndex >= minCount && tmpIndex<maxCount)
		{
			//填角色名和职业
			OfflineCharacterData * pCharacter=g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->_cid());
			if (pCharacter)
			{
				RankingListLevelData * pOtherData = rsp.add_levelist();
				pOtherData->set_cid(iter->_cid());
				pOtherData->set_level(iter->_value());

				pOtherData->set_prof(pCharacter->GetProf());
				pOtherData->set_username(pCharacter->GetCharName());
				pOtherData->set_camp(pCharacter->GetCampID());
				tmpIndex++;

				if (iter->_cid() == currentCid)
				{
					myindex = tmpIndex;
					pData->set_level(iter->_value());
				}

				iter++;
			}
			else
			{
				iter=m_vCurrentTimeLevel.erase(iter);
			}
		}
	}
	if (myindex==0)
	{
		myindex = 1000;  
	}

	rsp.set_levelrank(myindex);
}


//获取金币排行
void CRankingListMgr::OnReqGoldRankList(CharIDType currentCid, RankingListRsp & rsp)
{

	//if ((uint32_t)m_vGold.size() < g_constRankingListCount)
	//{
	//	GetGoldRankList();
	//}

	//int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	//int tmpIndex = 0;
	////先把自己的信息填最前面
	//RankingListGoldData * pData = rsp.add_goldlist();
	//pData->set_cid(currentCid);
	//OfflineCharacterData * pCharacterCurrent = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	//if (pCharacterCurrent)
	//{
	//	pData->set_gold(pCharacterCurrent->GetGold());
	//	pData->set_prof(pCharacterCurrent->GetProf());
	//	pData->set_username(pCharacterCurrent->GetCharName());
	//}
	//

	//int minCount = 0;
	//int maxCount = g_constRankingListCount;
	//vecCharacterID::iterator iter = m_.begin();
	//for (; iter != m_vLevel.end(); ++iter)
	//{
	//	if (tmpIndex >= minCount && tmpIndex < maxCount)
	//	{
	//		

	//		//填角色名和职业
	//		OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->_cid());
	//		if (pCharacter)
	//		{
	//			RankingListGoldData * pOtherData = rsp.add_goldlist();
	//			pOtherData->set_cid(iter->_cid());
	//			pOtherData->set_gold(iter->_value());

	//			pOtherData->set_prof(pCharacter->GetProf());
	//			pOtherData->set_username(pCharacter->GetCharName());
	//		}
	//	}
	//	tmpIndex++;

	//	if (iter->_cid() == currentCid)
	//	{
	//		myindex = tmpIndex;
	//	}

	//}
	//if (myindex == 0)
	//{
	//	myindex = 1000;
	//}

	//rsp.set_levelrank(myindex);
}

void CRankingListMgr::OnReqAllKillPoint(CharIDType currentCid, RankingListRsp & rsp)
{
	if ((uint32_t)m_vAllKill.size() < g_constRankingListCount)
	{
		GetAllKillPointRandList();
	}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListKillPoingData * pData = rsp.add_allpointlist();
	g_GetCampMgr()->GetPlayerCampInfo(currentCid, enRankingListType::enRankingListType_AllKillPoint,*pData);

	if (pData->point() ==0 )
	{
		myindex = -1;
	}

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecKillPoint::iterator iter = m_vAllKill.begin();
	for (; iter != m_vAllKill.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{

			//OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->cid());
			//if (pCharacter)
			{
				RankingListKillPoingData * pData = rsp.add_allpointlist();
				//pData->set_cid(iter->cid());
				//pData->set_point(iter->point());
				//pData->set_prof(iter->prof());
				//pData->set_username(iter->username());

				//pData->set_camp(pCharacter->GetCampID());
				if (pData)
				{
					pData->CopyFrom(*iter);
				}
				

				tmpIndex++;
			}
		}
		
		if (iter->cid() == currentCid)
		{
			myindex = tmpIndex;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}
void CRankingListMgr::OnReqLightKillPoint(CharIDType currentCid, RankingListRsp & rsp)
{
	if ((uint32_t)m_vLightKill.size() < g_constRankingListCount)
	{
		GetLightKillPointRandList();
	}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListKillPoingData * pData = rsp.add_allpointlist();
	g_GetCampMgr()->GetPlayerCampInfo(currentCid, enRankingListType::enRankingListType_LightKillPoint, *pData);
	if (pData->point() == 0)
	{
		myindex = -1;
	}

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecKillPoint::iterator iter = m_vLightKill.begin();
	for (; iter != m_vLightKill.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			RankingListKillPoingData * pData = rsp.add_allpointlist();
			//pData->set_cid(iter->cid());
			//pData->set_point(iter->point());
			//pData->set_prof(iter->prof());
			//pData->set_username(iter->username());
			//pData->set_camp(ECamp_Type_Light);
			pData->CopyFrom(*iter);
		}
		tmpIndex++;

		if (iter->cid() == currentCid)
		{
			myindex = tmpIndex;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}
void CRankingListMgr::OnReqBlackKillPoint(CharIDType currentCid, RankingListRsp & rsp)
{
	if ((uint32_t)m_vBlackKill.size() < g_constRankingListCount)
	{
		GetBlackkillPointRandList();
	}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListKillPoingData * pData = rsp.add_allpointlist();
	g_GetCampMgr()->GetPlayerCampInfo(currentCid, enRankingListType::enRankingListType_BlackKillPoint, *pData);
	if (pData->point() == 0)
	{
		myindex = -1;
	}

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecKillPoint::iterator iter = m_vBlackKill.begin();
	for (; iter != m_vBlackKill.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			RankingListKillPoingData * pData = rsp.add_allpointlist();
			//pData->set_cid(iter->cid());
			//pData->set_point(iter->point());
			//pData->set_prof(iter->prof());
			//pData->set_username(iter->username());
			//pData->set_camp(ECamp_Type_Dark);
			pData->CopyFrom(*iter);
		}
		tmpIndex++;

		if (iter->cid() == currentCid)
		{
			myindex = tmpIndex;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}

//获取声望排行
void CRankingListMgr::OnReqAllPristige(CharIDType currentCid, RankingListRsp & rsp)
{
	if ((uint32_t)m_vAllPristige.size() < g_constRankingListCount)
	{
		GetAllPrestige();
	}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListKillPoingData * pData = rsp.add_allpointlist();
	//填角色名和职业
	g_GetCampMgr()->GetPlayerCampInfo(currentCid, enRankingListType::enRankingListType_AllPrestige, *pData);
	if (pData->point() == 0)
	{

		//OfflineCharacterData * pCharacterMy = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
		//if (pCharacterMy)
		//{
		//	pData->set_camp(pCharacterMy->GetCampID());
		//}
		//else
		//{
		//	pData->set_camp(ECamp_Type_None);
		//}
		myindex = -1;
	}

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecKillPoint::iterator iter = m_vAllPristige.begin();
	for (; iter != m_vAllPristige.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{

			//OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->cid());
			//if (pCharacter)
			{

				RankingListKillPoingData * pData = rsp.add_allpointlist();
				//pData->set_cid(iter->cid());
				//pData->set_point(iter->point());
				//pData->set_prof(iter->prof());
				//pData->set_username(iter->username());
				//pData->set_camp(pCharacter->GetCampID());
				pData->CopyFrom(*iter);
				tmpIndex++;
			}
		}
		
		if (iter->cid() == currentCid)
		{
			myindex = tmpIndex;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}
void CRankingListMgr::OnReqLightPristige(CharIDType currentCid, RankingListRsp & rsp)
{
	if ((uint32_t)m_vLightPristige.size() < g_constRankingListCount)
	{
		GetLigthPrestige();
	}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListKillPoingData * pData = rsp.add_allpointlist();
	//填角色名和职业
	g_GetCampMgr()->GetPlayerCampInfo(currentCid, enRankingListType::enRankingListType_LightPrestige, *pData);
	if (pData->point() == 0)
	{
		myindex = -1;
		//pData->set_camp(ECamp_Type_Light);
	}

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecKillPoint::iterator iter = m_vLightPristige.begin();
	for (; iter != m_vLightPristige.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			RankingListKillPoingData * pData = rsp.add_allpointlist();
			//pData->set_cid(iter->cid());
			//pData->set_point(iter->point());
			//pData->set_prof(iter->prof());
			//pData->set_username(iter->username());
			//pData->set_camp(ECamp_Type_Light);
			pData->CopyFrom(*iter);
		}
		tmpIndex++;

		if (iter->cid() == currentCid)
		{
			myindex = tmpIndex;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}
void CRankingListMgr::OnReqBlackPristige(CharIDType currentCid, RankingListRsp & rsp)
{
	if ((uint32_t)m_vBlackPristige.size() < g_constRankingListCount)
	{
		GetBlackPrestige();
	}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListKillPoingData * pData = rsp.add_allpointlist();
	//填角色名和职业
	g_GetCampMgr()->GetPlayerCampInfo(currentCid, enRankingListType::enRankingListType_BlackPrestige, *pData);
	if (pData->point() == 0)
	{
		//pData->set_camp(ECamp_Type_Dark);
		myindex = -1;
	}

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecKillPoint::iterator iter = m_vBlackPristige.begin();
	for (; iter != m_vBlackPristige.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			RankingListKillPoingData * pData = rsp.add_allpointlist();
			//pData->set_cid(iter->cid());
			//pData->set_point(iter->point());
			//pData->set_prof(iter->prof());
			//pData->set_username(iter->username());
			//pData->set_camp(ECamp_Type_Dark);
			pData->CopyFrom(*iter);
		}
		tmpIndex++;

		if (iter->cid() == currentCid)
		{
			myindex = tmpIndex;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}


//获取钻石排行
void CRankingListMgr::OnReqDiamondRankList(CharIDType currentCid, RankingListRsp & rsp)
{
	//if ((uint32_t)m_vDiamond.size() < g_constRankingListCount)
	//{
	//	GetDiamondRandList();
	//}

	//int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	//int tmpIndex = 0;
	////先把自己的信息填最前面
	//RankingListDiamondData * pData = rsp.add_dimaondlist();
	//pData->set_cid(currentCid);

	//OfflineCharacterData * pCharacterCurrent = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	//if (pCharacterCurrent)
	//{
	//	pData->set_diamond(pCharacterCurrent->GetDiamond());
	//	pData->set_prof(pCharacterCurrent->GetProf());
	//	pData->set_username(pCharacterCurrent->GetCharName());
	//}

	//int minCount = 0;
	//int maxCount = g_constRankingListCount ;
	//vecCharacterID::iterator iter = m_vLevel.begin();
	//for (; iter != m_vLevel.end(); ++iter)
	//{
	//	if (tmpIndex >= minCount && tmpIndex < maxCount)
	//	{
	//		//填角色名和职业
	//		OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->_cid());
	//		if (pCharacter)
	//		{
	//			RankingListDiamondData * pOtherData = rsp.add_dimaondlist();
	//			pOtherData->set_cid(iter->_cid());
	//			pOtherData->set_diamond(iter->_value());
	//			pOtherData->set_prof(pCharacter->GetProf());
	//			pOtherData->set_username(pCharacter->GetCharName());
	//		}
	//	}
	//	tmpIndex++;

	//	if (iter->_cid() == currentCid)
	//	{
	//		myindex = tmpIndex;
	//	}

	//}
	//if (myindex == 0)
	//{
	//	myindex = 1000;
	//}

	//rsp.set_levelrank(myindex);
}



//获取战斗排名
void CRankingListMgr::OnReqFightRankList(CharIDType currentCid, RankingListRsp & rsp, enRankingListType type)
{
	//for (int i = 0; i < ECHARACTER_PROF_ARCHER; ++i)
	//{
	//	if ((uint32_t)m_arrFightValue[i].size()<g_constRankingListCount)
	//	{
	//		GetFightRankList();
	//	}
	//}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	int prottype = 0;
	//先把自己的信息填最前面
	RankingListFightValueData * pData = NULL;
	if (type == enRankingListType::enRankingListType_WarriorFight)
	{
		pData = rsp.add_proffight1list();
		prottype = 0;
	}
	else if (type == enRankingListType::enRankingListType_MagicianFight)
	{
		pData = rsp.add_proffight2list();
		prottype = 1;
	}
	else if (type == enRankingListType::enRankingListType_AssassinFight)
	{
		pData = rsp.add_proffight3list();
		prottype = 2;
	}
	else if (type == enRankingListType::enRankingListType_ArcgerFight)
	{
		pData = rsp.add_proffight4list();
		prottype = 3;
	}
	if (!pData)
	{
		return;
	}
	pData->set_cid(currentCid);
	OfflineCharacterData * pCharacterCurrent = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (!pCharacterCurrent)
	{
		return;
	}
	pData->set_fightvalue(pCharacterCurrent->GetFight());
	pData->set_username(pCharacterCurrent->GetCharName());
	pData->set_camp(pCharacterCurrent->GetCampID());
	if (prottype + 1 != pCharacterCurrent->GetProf())
	{
		myindex = -1;
	}

	

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecCharacterID::iterator iter = m_arrCurrentTimeFightValue[prottype].begin();
	for (; iter != m_arrCurrentTimeFightValue[prottype].end(); )
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			RankingListFightValueData * pOtherData = NULL;
			//填角色名和职业
			OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->_cid());
			if (pCharacter)
			{

				if (type == enRankingListType::enRankingListType_WarriorFight)
				{
					pOtherData = rsp.add_proffight1list();
				}
				else if (type == enRankingListType::enRankingListType_MagicianFight)
				{
					pOtherData = rsp.add_proffight2list();
				}
				else if (type == enRankingListType::enRankingListType_AssassinFight)
				{
					pOtherData = rsp.add_proffight3list();
				}
				else if (type == enRankingListType::enRankingListType_ArcgerFight)
				{
					pOtherData = rsp.add_proffight4list();
				}
				if (!pOtherData)
				{
					continue;
				}
				pOtherData->set_username(pCharacter->GetCharName());
				pOtherData->set_cid(iter->_cid());
				pOtherData->set_fightvalue(iter->_value());
				pOtherData->set_camp(pCharacter->GetCampID());
				tmpIndex++;
				if (iter->_cid() == currentCid)
				{
					myindex = tmpIndex;
					pData->set_fightvalue(iter->_value());
				}

				iter++;
			}
			else
			{
				iter=m_arrCurrentTimeFightValue[prottype].erase(iter);
			}
		}
		else
		{
			break;
		}
		
	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}


//获取总战力排行
void CRankingListMgr::OnReqAllProRankList(CharIDType currentCid, RankingListRsp & rsp)
{
	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListAllProFightData * pData = rsp.add_allprofightlist();
	pData->set_cid(currentCid);
	OfflineCharacterData * pCharacterCurrent = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (!pCharacterCurrent)
	{
		return;
	}

	pData->set_fightvalue(pCharacterCurrent->GetFight());
	pData->set_username(pCharacterCurrent->GetCharName());
	pData->set_prop(pCharacterCurrent->GetProf());
	pData->set_camp(pCharacterCurrent->GetCampID());
	

	int minCount = 0;
	int maxCount = g_constRankingListCount;
	vecCharacterID::iterator iter = m_arrAllProFight.begin();
	for (; iter != m_arrAllProFight.end(); )
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			RankingListAllProFightData * pOtherData = NULL;
			//填角色名和职业
			OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->_cid());
			if (pCharacter)
			{
				pOtherData = rsp.add_allprofightlist();
				if (!pOtherData)
				{
					continue;
				}
				pOtherData->set_username(pCharacter->GetCharName());
				pOtherData->set_cid(iter->_cid());
				pOtherData->set_fightvalue(iter->_value());
				pOtherData->set_prop(pCharacter->GetProf());
				pOtherData->set_camp(pCharacter->GetCampID());
				tmpIndex++;
				if (iter->_cid() == currentCid)
				{
					myindex = tmpIndex;
					pData->set_fightvalue(iter->_value());
				}

				iter++;
			}
			else
			{
				iter=m_arrAllProFight.erase(iter);
			}
		}
		else
		{
			break;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}


//获取成就排行
void CRankingListMgr::OnReqAchievementRandList(CharIDType currentCid, RankingListRsp & rsp, enRankingListType type)
{
	//for (int i = 0; i < ACHIEVEMENT_TYPE_ADVENTURE; ++i)
	//{
	//	if ((uint32_t)m_arrAchievementPoint[i].size() < g_constRankingListCount)
	//	{
	//		GetAchievementRandList();
	//		break;
	//	}
	//}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	int typeIndex = 0;
	//先把自己的信息填最前面
	RankingListAchievementPoingData * pData = NULL;
	if (type == enRankingListType::enRankingListType_achievement_person)
	{
		pData = rsp.add_achievementpoint1list();
		typeIndex = ACHIEVEMENT_TYPE_PERSION - 1;
	}
	else if (type == enRankingListType::enRankingListType_achievement_social)
	{
		pData = rsp.add_achievementpoint2list();
		typeIndex = ACHIEVEMENT_TYPE_SOCIAL - 1;
	}
	else if (type == enRankingListType::enRankingListType_achievement_evelop)
	{
		pData = rsp.add_achievementpoint3list();
		typeIndex = ACHIEVEMENT_TYPE_EQUIP - 1;
	}
	else if (type == enRankingListType::enRankingListType_achievement_general)
	{
		pData = rsp.add_achievementpoint4list();
		typeIndex = ACHIEVEMENT_TYPE_ADVENTURE - 1;
	}
	if (!pData)
	{
		return;
	}
	pData->set_cid(currentCid);
	OfflineCharacterData * pCurrentCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (!pCurrentCharacter)
	{
		return;
	}
	pData->set_point(pCurrentCharacter->GetAchievementPoint((AchievementType)(typeIndex+1)));
	pData->set_username(pCurrentCharacter->GetCharName());
	pData->set_prof(pCurrentCharacter->GetProf());
	pData->set_camp(pCurrentCharacter->GetCampID());
	

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	vecCharacterID::iterator iter = m_arrCurrentTimeAchievementPoint[typeIndex].begin();
	for (; iter != m_arrCurrentTimeAchievementPoint[typeIndex].end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			RankingListAchievementPoingData * pOtherData = NULL;

			if (type == enRankingListType::enRankingListType_achievement_person)
			{
				pOtherData = rsp.add_achievementpoint1list();
			}
			else if (type == enRankingListType::enRankingListType_achievement_social)
			{
				pOtherData = rsp.add_achievementpoint2list();
			}
			else if (type == enRankingListType::enRankingListType_achievement_evelop)
			{
				pOtherData = rsp.add_achievementpoint3list();
			}
			else if (type == enRankingListType::enRankingListType_achievement_general)
			{
				pOtherData = rsp.add_achievementpoint4list();
			}
			if (!pOtherData)
			{
				continue;
			}
			pOtherData->set_cid(iter->_cid());
			pOtherData->set_point(iter->_value());

			if (iter->_cid()==currentCid)
			{
				pData->set_point(iter->_value());
			}

			//填角色名和职业
			OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->_cid());
			if (pCharacter)
			{
				pOtherData->set_username(pCharacter->GetCharName());
				pOtherData->set_prof(pCharacter->GetProf());
				pOtherData->set_camp(pCharacter->GetCampID());
			}
		}
		tmpIndex++;

		if (iter->_cid() == currentCid)
		{
			myindex = tmpIndex;
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}


//获取竟技场排名
void CRankingListMgr::OnReqArenaRankingList(CharIDType currentCid, RankingListRsp & rsp)
{
	//if (m_vArenaRankInfo.size()<g_constRankingListCount)
	{
		m_vArenaRankInfo.clear();
		g_GetArenaMgr()->GetArenaRankList(m_vArenaRankInfo);
	}

	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListArenaData * pMyselfData = rsp.add_arenadata();
	
	pMyselfData->set_cid(currentCid);
	OfflineCharacterData * pCurrentCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (!pCurrentCharacter)
	{
		return;
	}

	pMyselfData->set_fightvalue(pCurrentCharacter->GetFight());
	pMyselfData->set_username(pCurrentCharacter->GetCharName());
	pMyselfData->set_prof(pCurrentCharacter->GetProf());
	pMyselfData->set_camp(pCurrentCharacter->GetCampID());
	

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	std::vector<ArenaRankInfo>::iterator iter = m_vArenaRankInfo.begin();
	for (; iter != m_vArenaRankInfo.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			//填角色名和职业
			RankingListArenaData * pdata = rsp.add_arenadata();
			pdata->set_cid(iter->dstid());
			pdata->set_username(iter->dstname());
			pdata->set_prof(iter->prof());
			pdata->set_fightvalue(iter->fight());
			pdata->set_type(iter->type());
			if (iter->type() == ARENA_CHALLENGE_TYPE_ROBOT)
			{
				pdata->set_camp(ECamp_Type_None);
			}
			else
			{
				OfflineCharacterData * pOther = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(iter->dstid());
				if (pOther)
				{
					pdata->set_camp(pOther->GetCampID());
				}
				else
				{
					pdata->set_camp(ECamp_Type_None);
				}
			}
		}
		tmpIndex++;

		if (iter->dstid() == currentCid)
		{
			myindex = tmpIndex;
			pMyselfData->set_fightvalue(iter->fight());
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);

}

//获取公会玩家可用贡献
void CRankingListMgr::OnReqClanCanUseContributeRankingList(CharIDType currentCid, RankingListRsp & rsp)
{
	//if (m_vClanContribute.size()<g_constRankingListCount)
	//{
	//	GetClanCanUseContriubte();
	//}

	//下发给客户端
	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListClanContribute * pMyselfData = rsp.add_clancontributedata();

	//pMyselfData->set_cid(currentCid);
	OfflineCharacterData * pCurrentCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (!pCurrentCharacter)
	{
		return;
	}
	std::string strClanName = "";
	std::string strLeadName = "";
	uint32_t canUseContribute = 0;
	uint32_t weekContribute = 0;
	g_GetUnionMgr()->GetUnionParamForRank(currentCid, strClanName, strLeadName, canUseContribute, weekContribute);

	pMyselfData->set_clanname(strClanName);
	pMyselfData->set_username(pCurrentCharacter->GetCharName());
	pMyselfData->set_contributevalue(canUseContribute);
	pMyselfData->set_camp(pCurrentCharacter->GetCampID());
	if (strClanName.empty())
	{
		myindex = -1;
	}
	

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	std::vector<RankingListClanContribute>::iterator iter = m_vClanCurrentTimeContribute.begin();
	for (; iter != m_vClanCurrentTimeContribute.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			//填角色名和职业
			RankingListClanContribute * pdata = rsp.add_clancontributedata();
			pdata->CopyFrom(*iter);
		}
		tmpIndex++;

		if (!strcmp(iter->username().c_str(), pCurrentCharacter->GetCharName()))
		{
			myindex = tmpIndex;
			pMyselfData->set_contributevalue(iter->contributevalue());
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}

//获取公会玩家周贡献
void CRankingListMgr::OnReqClanWeekContributeRankingList(CharIDType currentCid, RankingListRsp & rsp)
{
	//if (m_vClanContribute.size() < g_constRankingListCount)
	//{
	//	GetClanWeekContribute();
	//}

	//下发给客户端
	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListClanContribute * pMyselfData = rsp.add_clanweekcontributedata();

	//pMyselfData->set_cid(currentCid);
	OfflineCharacterData * pCurrentCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (!pCurrentCharacter)
	{
		return;
	}
	std::string strClanName = "";
	std::string strLeadName = "";
	uint32_t canUseContribute = 0;
	uint32_t weekContribute = 0;
	g_GetUnionMgr()->GetUnionParamForRank(currentCid, strClanName, strLeadName, canUseContribute, weekContribute);

	pMyselfData->set_clanname(strClanName);
	pMyselfData->set_username(pCurrentCharacter->GetCharName());
	pMyselfData->set_contributevalue(weekContribute);
	pMyselfData->set_camp(pCurrentCharacter->GetCampID());
	if (strClanName.empty())
	{
		myindex = -1;
	}
	

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	std::vector<RankingListClanContribute>::iterator iter = m_vClanCurrentTimeWeekContribute.begin();
	for (; iter != m_vClanCurrentTimeWeekContribute.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			//填角色名和职业
			RankingListClanContribute * pdata = rsp.add_clanweekcontributedata();
			//pdata->set_clanname(iter->clanname());
			//pdata->set_username(iter->username());
			//pdata->set_contributevalue(iter->contributevalue());
			pdata->CopyFrom(*iter);
		}
		tmpIndex++;

		if (!strcmp(iter->username().c_str(), pCurrentCharacter->GetCharName()))
		{
			myindex = tmpIndex;
			pMyselfData->set_contributevalue(iter->contributevalue());
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}

//获取公会战力排行
void CRankingListMgr::OnReqClanFightRankingList(CharIDType currentCid, RankingListRsp & rsp)
{
	if (m_vClanRank.size() <= 0)
	{
		GetClanRankignList();
	}

	//下发给客户端
	int myindex = 0;  //记录自己的排名，如果不在前100名，则发送这个值给客户端
	int tmpIndex = 0;
	//先把自己的信息填最前面
	RankingListClanData * pMyselfData = rsp.add_clandata();
	std::string strClanName = "";
	std::string strLeadName = "";
	uint32_t canUseContribute = 0;
	uint32_t weekContribute = 0;
	//pMyselfData->set_cid(currentCid);
	OfflineCharacterData * pCurrentCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(currentCid);
	if (!pCurrentCharacter)
	{
		return;
	}
		g_GetUnionMgr()->GetUnionParamForRank(currentCid, strClanName, strLeadName, canUseContribute, weekContribute);
		
		pMyselfData->set_clanname(strClanName);
		pMyselfData->set_fightvalue(GetUnionFight(strClanName));
		pMyselfData->set_clanleadername(strLeadName);
		pMyselfData->set_camp(pCurrentCharacter->GetCampID());
		if (strClanName.empty())
		{
			myindex = -1;
		}
	

	int minCount = 0;
	int maxCount = g_constRankingListCount ;
	std::vector<RankingListClanData>::iterator iter = m_vClanRank.begin();
	for (; iter != m_vClanRank.end(); ++iter)
	{
		if (tmpIndex >= minCount && tmpIndex < maxCount)
		{
			//填角色名和职业
			RankingListClanData * pdata = rsp.add_clandata();
			//pdata->set_clanname(iter->clanname());
			//pdata->set_fightvalue(iter->fightvalue());
			//pdata->set_clanleadername(iter->clanleadername());
			//pdata->set_camp(iter->camp());
			pdata->CopyFrom(*iter);
		}
		tmpIndex++;

		if (!strcmp(iter->clanname().c_str(), strClanName.c_str()))
		{
			myindex = tmpIndex;
			pMyselfData->set_fightvalue(iter->fightvalue());
		}

	}
	if (myindex == 0)
	{
		myindex = 1000;
	}

	rsp.set_levelrank(myindex);
}


//加入公会,传入的是历史贡献
void CRankingListMgr::AddClan(RankingListClanContribute & value)
{
	ChangeClanContribute(value);
	value.set_contributevalue(0); //刚进来，周贡献为0
	ChangeClanWeekContribute(value);
}
//离开公会,角色名
void CRankingListMgr::LeaveClan(string userName)
{
	std::vector<RankingListClanContribute>::iterator iter = m_vClanCurrentTimeContribute.begin();

	for (; iter != m_vClanCurrentTimeContribute.end(); ++iter)
	{
		if (!strcmp(iter->username().c_str(), userName.c_str()))
		{
			m_vClanCurrentTimeContribute.erase(iter);
			break;
		}
	}

	//先判断是否在队列中
	std::vector<RankingListClanContribute>::iterator iterWeek = m_vClanCurrentTimeWeekContribute.begin();

	for (; iterWeek != m_vClanCurrentTimeWeekContribute.end(); ++iterWeek)
	{
		if (!strcmp(iterWeek->username().c_str(), userName.c_str()))
		{
			m_vClanCurrentTimeWeekContribute.erase(iterWeek);
			break;
		}
	}
}


//解散公会
//void CRankingListMgr::DistroyUnion(string unionName)
//{
//	GetClanRankignList();
//
//	//把该公会的所有成员删除
//	std::vector<RankingListClanContribute>::iterator iter = m_vClanCurrentTimeContribute.begin();
//
//	for (; iter != m_vClanCurrentTimeContribute.end();)
//	{
//		if (!strcmp(iter->clanname().c_str(), unionName.c_str()))
//		{
//			iter = m_vClanCurrentTimeContribute.erase(iter);
//		}
//		else
//			++iter;
//	}
//
//	//先判断是否在队列中
//	std::vector<RankingListClanContribute>::iterator iterWeek = m_vClanCurrentTimeWeekContribute.begin();
//
//	for (; iterWeek != m_vClanCurrentTimeWeekContribute.end();)
//	{
//		if (!strcmp(iterWeek->clanname().c_str(), unionName.c_str()))
//		{
//			iterWeek = m_vClanCurrentTimeWeekContribute.erase(iterWeek);
//		}
//		else
//			++iterWeek;
//	}
//
//}


//公会成员累积贡献改变
void CRankingListMgr::ChangeClanContribute(RankingListClanContribute & value)
{
	
	//先判断是否在队列中
	std::vector<RankingListClanContribute>::iterator iter =m_vClanCurrentTimeContribute.begin();

	bool isFind = false;

	for (; iter != m_vClanCurrentTimeContribute.end();++iter)
	{
		if (!strcmp(iter->username().c_str(),value.username().c_str()))
		{
			isFind = true;
			break;
		}
	}

	if (!isFind)
	{
		//不在，则直接放末尾，再排序
		if (m_vClanCurrentTimeContribute.size()<g_constRankingListCount)
		{
			m_vClanCurrentTimeContribute.push_back(value);
			//排序
			SortClanContribute(m_vClanCurrentTimeContribute, value);
			return;
		}
		else
		{
			//放最后，再排序
			m_vClanCurrentTimeContribute.push_back(value);
			//排序
			SortClanContribute(m_vClanCurrentTimeContribute, value);
			m_vClanCurrentTimeContribute.erase(m_vClanCurrentTimeContribute.end() - 1);
		}
	}
	else  //如果在里面，则先删除
 	{
		m_vClanCurrentTimeContribute.erase(iter);
		m_vClanCurrentTimeContribute.push_back(value);
		//排序
		SortClanContribute(m_vClanCurrentTimeContribute, value);
	}
	
	m_bSaveFlag = true;

	return;
}


//公会成员改变周贡献
void CRankingListMgr::ChangeClanWeekContribute(RankingListClanContribute & value)
{
	//先判断是否在队列中
	std::vector<RankingListClanContribute>::iterator iter = m_vClanCurrentTimeWeekContribute.begin();

	bool isFind = false;

	for (; iter != m_vClanCurrentTimeWeekContribute.end(); ++iter)
	{
		if (!strcmp(iter->username().c_str(), value.username().c_str()))
		{
			isFind = true;
			break;
		}
	}


	if (!isFind)
	{
		//不在，则直接放末尾，再排序
		if (m_vClanCurrentTimeWeekContribute.size() < g_constRankingListCount)
		{
			m_vClanCurrentTimeWeekContribute.push_back(value);
			//排序
			SortClanContribute(m_vClanCurrentTimeWeekContribute, value);
			return;
		}
		else
		{
			//放最后，再排序
			m_vClanCurrentTimeWeekContribute.push_back(value);
			//排序
			SortClanContribute(m_vClanCurrentTimeWeekContribute, value);
			m_vClanCurrentTimeWeekContribute.erase(m_vClanCurrentTimeWeekContribute.end() - 1);
		}
	}
	else  //如果在里面，则先删除
	{
		m_vClanCurrentTimeWeekContribute.erase(iter);
		m_vClanCurrentTimeWeekContribute.push_back(value);
		//排序
		SortClanContribute(m_vClanCurrentTimeWeekContribute, value);
	}
	m_bSaveFlag = true;
	return;
}

//查询某个公会的战斗力
uint32_t CRankingListMgr::GetUnionFight(std::string strUnionName)
{
	std::vector<RankingListClanData>::iterator iter = m_vAllClanRank.begin();
	for (; iter != m_vAllClanRank.end();++iter)
	{
		if (!strcmp(iter->clanname().c_str(),strUnionName.c_str()))
		{
			return iter->fightvalue();
		}
	}
	return 0;
}

//重后往前找，找到自己最前的位置即可
void CRankingListMgr::SortV(vecCharacterID & vNode, uint32_t exp, bool sortAll)
{
	//if (exp==0)
	{
		//if (sortAll)  //全都重排
		//{
		//	for (int i = 0; i < (int)vNode.size(); ++i)
		//	{
		//		for (int j = i; j < (int)vNode.size(); ++j)
		//		{
		//			if (vNode[i]._value() < vNode[j]._value())
		//			{
		//				//换位
		//				stRankNode tmpNode = vNode[i];
		//				vNode[i] = vNode[j];
		//				vNode[j] = tmpNode;
		//			}
		//		}
		//	}
		//}
		//else
		{
			for (int i = (int)vNode.size() - 1; i >= 1; --i)
			{
				if (vNode[i]._value() > vNode[i - 1]._value())
				{
					//换位
					stRankNode tmpNode = vNode[i];
					vNode[i] = vNode[i - 1];
					vNode[i - 1] = tmpNode;
				}
				else
				{
					break;
				}
			}
		}
	}
	//else
	//{
	//	SortVExp(vNode,exp, sortAll);
	//}
}

//等级排名单独处理，因为这个等级相同，排经验，经验相同，排到达时间
void CRankingListMgr::SortVExp(vecCharacterID & vNode,uint32_t exp, bool sortAll)
{
	if (sortAll)
	{
		for (int i = 0; i < (int)vNode.size(); ++i)
		{
			for (int j = i; j < (int)vNode.size(); ++j)
			{
				bool bJudgeExp = true;
				OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(vNode[j]._cid());
				if (!pCharacter)
				{
					LogDebugFmtPrint("RandingList cid=%lu offline not find", vNode[j]._cid());
					bJudgeExp=false;
				}

				OfflineCharacterData * pCharacterI = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(vNode[i]._cid());
				if (!pCharacterI)
				{
					LogDebugFmtPrint("RandingList cid=%lu offline not find", vNode[i]._cid());
					bJudgeExp=false;
				}
				//这里有可能在离线玩家中找不到该玩家，导致后面判断有错，先这样处理，加打印，再找为什么 离线玩家里没有吧 todo..
				if (vNode[i]._value() < vNode[j]._value() || (bJudgeExp &&  vNode[i]._value() == vNode[j]._value() && pCharacterI->GetExp() < pCharacter->GetExp()))
				{
					//换位
					stRankNode tmpNode = vNode[i];
					vNode[i] = vNode[j];
					vNode[j] = tmpNode;
				}
			}
		}
	}
	else
	{
		for (int i = (int)vNode.size() - 1; i >= 1; --i)
		{
			bool bJudgeExp = true;
			OfflineCharacterData * pCharacter = g_GetOfflineCharacterDataMgr()->GetOfflineCharacter(vNode[i - 1]._cid());
			if (!pCharacter)
			{
				LogDebugFmtPrint("RandingList cid=%lu offline not find", vNode[i-1]._cid());
				bJudgeExp=false;
			}

			if (vNode[i]._value() > vNode[i - 1]._value() || (bJudgeExp && vNode[i]._value() == vNode[i - 1]._value() && exp > pCharacter->GetExp()))
			{
				//换位
				stRankNode tmpNode = vNode[i];
				vNode[i] = vNode[i - 1];
				vNode[i - 1] = tmpNode;
			}
			else
			{
				break;
			}
		}
	}
	
}

//重排
void CRankingListMgr::SortClanContribute(std::vector<RankingListClanContribute> & vClanContribute, RankingListClanContribute & value)
{
	//for (int i = 0;i< (int)vClanContribute.size(); ++i)
	//{
	//	for (int j = i; j<(int)vClanContribute.size();++j)
	//	{
	//		if (vClanContribute[i].contributevalue() < vClanContribute[j].contributevalue())
	//		{
	//			//换位
	//			RankingListClanContribute tmpNode = vClanContribute[i];
	//			vClanContribute[i] = vClanContribute[j];
	//			vClanContribute[j] = tmpNode;
	//		}
	//	}
	//}

	for (int i = (int)vClanContribute.size() - 1; i >= 1;--i)
	{
		if (vClanContribute[i].contributevalue() > vClanContribute[i-1].contributevalue())
		{
			//换位
			RankingListClanContribute tmpNode = vClanContribute[i];
			vClanContribute[i] = vClanContribute[i - 1];
			vClanContribute[i - 1] = tmpNode;
		}
	}
}

//获取公会排名
void CRankingListMgr::GetClanRankignList()
{
	m_vClanRank.clear();
	m_vAllClanRank.clear();
	g_GetUnionMgr()->SetAllUnionFight(m_vAllClanRank);

	//排序后，再取前100名
	std::sort(m_vAllClanRank.begin(), m_vAllClanRank.end(), CmpClanFight);
	uint32_t size = (uint32_t)m_vAllClanRank.size() > g_constRankingListCount ? g_constRankingListCount : (uint32_t)m_vAllClanRank.size();
	for (uint32_t i = 0; i < size; ++i)
	{
		if (m_vAllClanRank[i].fightvalue() > 0)
		{

			m_vClanRank.push_back(m_vAllClanRank[i]);
		}
		else
		{
			break;
		}
	}
}

void CRankingListMgr::GetClanCanUseContriubte()
{
	//m_vClanContribute.clear();
	//m_vClanContribute.insert(m_vClanContribute.begin(),m_vClanCurrentTimeContribute.begin(),m_vClanCurrentTimeContribute.end());
}

void CRankingListMgr::GetClanWeekContribute()
{
	//m_vClanWeekContribute.clear();
	//m_vClanWeekContribute.insert(m_vClanWeekContribute.begin(), m_vClanCurrentTimeWeekContribute.begin(), m_vClanCurrentTimeWeekContribute.end());
}

//获取前100名平均等级
uint32_t CRankingListMgr::GetAverageLevel()
{
	uint32_t sumLevel = 0;
	vecCharacterID::iterator iter = m_vCurrentTimeLevel.begin();
	for (; iter != m_vCurrentTimeLevel.end();++iter)
	{
		sumLevel += iter->_value();
	}
	if (m_vCurrentTimeLevel.size()<=0)
	{
		return 1;
	}

	return sumLevel / m_vCurrentTimeLevel.size();
}

//发放运营活动关于排行的奖励
void CRankingListMgr::GrantOperateActiveAword(uint32_t operateId)
{
	std::vector<int32_t> vOutParam;
	const OperateHuodongCfgInfo * pHoudongCfg = g_GetOperateHuodongCfgTable()->GetOperateHuodongCfgInfo(operateId);
	if (pHoudongCfg)
	{
		CommonApi::SplitStrToVecInt(pHoudongCfg->tiaoJian, ",", &vOutParam);
		
		for (int i = 0; i < (int)vOutParam.size();++i)
		{

			const OperateJiangliCfgInfo * pJianLiCfg=g_GetOperateJiangliCfgTable()->GetOperateJiangliCfgInfo(vOutParam[i]);
			if (pJianLiCfg)
			{
				vecCharacterID *pVec=nullptr;
				//取出前100名列表
				if (pHoudongCfg->nameId == OPERARE_ACTIVE_TYPE_FIGHTRANKING)
				{
					pVec = &m_arrAllProFight;

					m_bOperateActiveFightReword = true;
				}
				else if (pHoudongCfg->nameId == OPERARE_ACTIVE_TYPE_LEVELRANKING)
				{
					pVec = &m_vCurrentTimeLevel;

					m_bOperateActiveLevelReword = true;
 				}

				if (pVec)
				{
					//给指定名次发放奖励
					for (int i = pJianLiCfg->downNu - 1; i < pJianLiCfg->upNu;++i)
					{
						//人数还不够，则发完所有人为止
						if (i>=(int)pVec->size())
						{
							return;
						}

						//给这些人发奖励
						char buff[1024] = { 0 };
						if (pHoudongCfg->nameId == OPERARE_ACTIVE_TYPE_FIGHTRANKING)
						{
							snprintf(buff,1024,"恭喜您在战力排名活动中，排名为%d名，请查收活动奖励！",i+1);
						}
						else
						{
							snprintf(buff,1024, "恭喜您在等级排名活动中，排名为%d名，请查收活动奖励！", i + 1);
						}
						
						SendMail(pVec->at(i)._cid(), "系统", buff, pJianLiCfg->jiangLi);

						LogDebugFmtPrint("send CRankingListMgr::GrantOperateActiveAword id=%lu, 名次 index=%d", pVec->at(i)._cid(), i + 1);
					}
				}

			}

		}
	}

	//记录等级前三名 ,用于发称号
	int index = 0;
	for (int i = 0; i < (int)m_vCurrentTimeLevel.size();++i)
	{
		stRankNode node;
		node.set__cid(m_vCurrentTimeLevel[i]._cid());
		node.set__value(i + 1);

		if (!SendLogicServerRankingList(CenterToLogicRspRankingList::en_type_level, m_vCurrentTimeLevel[i]._cid(), i + 1))
		{
			m_vLevelTitle.push_back(node);
		}

		
		index++;
		if (index>3)
		{
			break;
		}
	}
	
	index = 0;
	for (int i = 0; i < (int)m_arrAllProFight.size();++i)
	{
		stRankNode node;
		node.set__cid(m_arrAllProFight[i]._cid());
		node.set__value(i + 1);
		if (!SendLogicServerRankingList(CenterToLogicRspRankingList::en_type_fight, m_arrAllProFight[i]._cid(), i + 1))
		{
			m_vFightTitle.push_back(node);
		}
		index++;
		if (index>3)
		{
			break;
		}
	}
}

void CRankingListMgr::CheckOperateActive(bool cheackTime)
{
	std::vector<int32_t> vOutParam;
	uint64_t nowTime = Time::Now().UnixSec();
	//判断战力排行时间到了没
	const OperateHuodongCfgMap * pHuodongCfg = g_GetOperateHuodongCfgTable()->GetOperateHuodongCfgMap();
	if (pHuodongCfg)
	{
		OperateHuodongCfgMap::const_iterator iter = pHuodongCfg->begin();
		for (; iter != pHuodongCfg->end(); ++iter)
		{
			if (iter->second.ifOpen && (iter->second.nameId == OPERARE_ACTIVE_TYPE_FIGHTRANKING || iter->second.nameId == OPERARE_ACTIVE_TYPE_LEVELRANKING))
			{
				if (m_bOperateActiveFightReword  && iter->second.nameId == OPERARE_ACTIVE_TYPE_FIGHTRANKING) //处理过了的不用处理
				{
					continue;
				}
				else if (m_bOperateActiveLevelReword && iter->second.nameId == OPERARE_ACTIVE_TYPE_LEVELRANKING)
				{
					continue;
				}

				
				vOutParam.clear();
				//解析结束时间
				CommonApi::SplitStrToVecInt(iter->second.timeB, "/", &vOutParam);
				if ((int)vOutParam.size() < 3)
				{
					LogErrFmtPrint("operate timeB  param error size=%d ", vOutParam.size());
					continue;
				}

				//时间到了，给战力排行奖励
				uint64_t finishTime = Time::GetSecTime(vOutParam[0], vOutParam[1], vOutParam[2], 23, 59, 59);

				if (cheackTime) //需要检测活动时间
				{
					if (nowTime - finishTime <= 10)
					{
						GrantOperateActiveAword(iter->first);
						SaveDB(Time::Now().UnixSec());
					}
				}
				else
				{
					//时间超过结束时间，且没发过奖励，直接发，不用再判断时间
					//if (nowTime>finishTime)
					//{
					//	GrantOperateActiveAword(iter->first);
					//	SaveDB(Time::Now().UnixSec());
					//}
					//
				}
			}
		}
	}
}

//发邮件奖励
void CRankingListMgr::SendMail(CharIDType destCharid, string strMailMotif, string strContent, uint32_t boxId)
{
	VEC_ITEM_PROTO_EX vecProtoEx;
	vecProtoEx.clear();
	int32_t goldNum=0;
	int32_t diamondNum = 0;
	int32_t bindDiamondNum = 0;
	BoxCondCfg boxCond;
	g_GetOfflineCharacterDataMgr()->GetBoxCond(destCharid, boxCond);
	g_GetItemMgr()->CreateBoxDropItem(boxId, vecProtoEx, goldNum, diamondNum, bindDiamondNum, boxCond);

	g_GetMailMgr()->SendSystemMail(destCharid, strMailMotif, strContent,goldNum,0, diamondNum, bindDiamondNum, 0, vecProtoEx, MAIL_SOURCE_RANKINGLIST);
}

//通知逻辑服某玩家的排行等级，用于加称号
bool CRankingListMgr::SendLogicServerRankingList(uint32_t type, CharIDType cid, uint32_t index)
{
	//只发在线的
	ActiveCharacter* pOnline=g_GetActiveCharacterMgr()->GetOnlineCharacter(cid);
	if (pOnline)
	{
		CenterToLogicRspRankingList rsp;
		rsp.set_cid(cid);
		rsp.set_index(index);
		rsp.set_type(type);
		g_GetCenterService()->SendDataToLogicByCharID(cid, EMODULE_ID_RANKINGLIST, CENTER_LOGIC_RSP_RANKINGLIST_INDEX, &rsp);
		return true;
	}
	return false;
	
}
